apidir = @htmldir@/api

man_pages = \
	dbus-cleanup-sockets.1 \
	dbus-daemon.1 \
	dbus-launch.1 \
	dbus-monitor.1 \
	dbus-run-session.1 \
	dbus-send.1 \
	dbus-test-tool.1 \
	dbus-update-activation-environment.1 \
	dbus-uuidgen.1 \
	$(NULL)

MAN_XML_FILES = $(patsubst %.1,%.1.xml,$(man_pages))

if DBUS_XML_DOCS_ENABLED
man1_MANS = $(man_pages)
endif

MAN_HTML_FILES = $(patsubst %.1,%.1.html,$(man_pages))

dtddir = $(datadir)/xml/dbus-1
dist_dtd_DATA = \
	busconfig.dtd \
	introspect.dtd

dist_doc_DATA = system-activation.txt

# uploaded and distributed, but not installed
STATIC_DOCS = \
	dbus-faq.xml \
	dbus-specification.xml \
	dbus-test-plan.xml \
	dbus-tutorial.xml \
	dbus-api-design.duck \
	dcop-howto.txt \
	introspect.xsl

EXTRA_DIST = \
	file-boilerplate.c \
	doxygen_to_devhelp.xsl \
	$(STATIC_DOCS)

html_DATA =

dist_html_DATA =

# diagram.png/diagram.svg aren't really HTML, but must go in the same
# directory as the HTML to avoid broken links
STATIC_HTML = \
	diagram.png \
	diagram.svg \
	$(NULL)

# Static HTML helper files generated by yelp-build.
YELP_STATIC_HTML = \
	yelp.js \
	C.css \
	highlight.pack.js \
	jquery.js \
	jquery.syntax.js \
	jquery.syntax.brush.html.js \
	jquery.syntax.core.js \
	jquery.syntax.layout.yelp.js \
	$(NULL)

dist_html_DATA += $(STATIC_HTML)

# Content HTML files generated by yelp-build.
YELP_HTML = \
	dbus-api-design.html \
	$(NULL)

XMLTO_HTML =					\
	dbus-faq.html				\
	dbus-specification.html			\
	dbus-test-plan.html			\
	dbus-tutorial.html			\
	$(MAN_HTML_FILES)			\
	$(NULL)

if DBUS_XML_DOCS_ENABLED
html_DATA += $(XMLTO_HTML)

%.html: %.xml
	$(XMLTO) html-nochunks $<

%.1: %.1.xml
	$(XMLTO) man $<
endif

if DBUS_DOXYGEN_DOCS_ENABLED
all-local:: doxygen.stamp

doxygen.stamp: $(wildcard $(top_srcdir)/dbus/*.[ch])
	$(AM_V_GEN)cd $(top_builddir) && doxygen Doxyfile
	@touch $@

if DBUS_HAVE_XSLTPROC
html_DATA += dbus.devhelp2

dbus.devhelp2: $(srcdir)/doxygen_to_devhelp.xsl doxygen.stamp
	$(XSLTPROC) -o $@ $< api/xml/index.xml
endif

if DBUS_DUCKTYPE_DOCS_ENABLED
html_DATA += $(YELP_HTML)

%.page: %.duck
	$(DUCKTYPE) -o $@ $<
%.html: %.page
	$(YELP_BUILD) html $<
$(YELP_STATIC_HTML): $(YELP_HTML)
endif

# this assumes CREATE_SUBDIRS isn't set to YES in Doxyfile
# (which it isn't currently)
install-data-local:: doxygen.stamp
	$(MKDIR_P) $(DESTDIR)$(apidir)
	$(INSTALL_DATA) api/html/* $(DESTDIR)$(apidir)
if DBUS_QTHELP_DOCS_ENABLED
	$(MKDIR_P) $(DESTDIR)$(qchdir)
	$(INSTALL_DATA) $(DOXYGEN_QCH_FILE) $(DESTDIR)$(qchdir)
endif
if DBUS_DUCKTYPE_DOCS_ENABLED
	$(AM_V_at)for x in $(YELP_STATIC_HTML); do \
		if test -e "$$x"; then \
			$(INSTALL_DATA) "$$x" $(DESTDIR)$(htmldir); \
		fi; \
	done
endif

uninstall-local::
	rm -f $(DESTDIR)$(apidir)/*.html
	rm -f $(DESTDIR)$(apidir)/*.png
	rm -f $(DESTDIR)$(apidir)/*.css
	rm -f $(DESTDIR)$(apidir)/*.js
	rm -f $(DESTDIR)$(htmldir)/*.css
	rm -f $(DESTDIR)$(htmldir)/*.js
	rm -f $(DESTDIR)$(htmldir)/*.html
	rm -f $(DESTDIR)$(docdir)/*.txt
	rm -f $(DESTDIR)$(htmldir)/*.png
	rm -f $(DESTDIR)$(htmldir)/*.svg
	rm -f $(DESTDIR)$(apidir)/*.qhp
	rm -f $(DESTDIR)$(qchdir)/dbus-*.qch
	rmdir --ignore-fail-on-non-empty $(DESTDIR)$(apidir) || \
		rmdir $(DESTDIR)$(apidir)
endif

if DBUS_CAN_UPLOAD_DOCS
BONUS_FILES = \
	$(top_srcdir)/README \
	$(top_srcdir)/CONTRIBUTING.md \
	$(top_srcdir)/AUTHORS \
	$(top_srcdir)/NEWS \
	$(top_srcdir)/COPYING \
	$(NULL)

dbus-docs: $(STATIC_DOCS) $(dist_dtd_DATA) $(MAN_XML_FILES) $(dist_doc_DATA) $(dist_html_DATA) $(MAN_HTML_FILES) $(BONUS_FILES) doxygen.stamp $(XMLTO_HTML) $(YELP_HTML)
	$(AM_V_at)rm -rf $@ $@.tmp
	$(AM_V_GEN)$(MKDIR_P) $@.tmp/api
	$(AM_V_at)cd $(srcdir) && cp $(STATIC_DOCS) @abs_builddir@/$@.tmp
	$(AM_V_at)cd $(srcdir) && cp $(dist_dtd_DATA) @abs_builddir@/$@.tmp
	$(AM_V_at)cd $(srcdir) && cp $(dist_doc_DATA) @abs_builddir@/$@.tmp
	$(AM_V_at)cd $(srcdir) && cp $(STATIC_HTML) @abs_builddir@/$@.tmp
	$(AM_V_at)cp $(XMLTO_HTML) @abs_builddir@/$@.tmp
	$(AM_V_at)cp $(YELP_HTML) @abs_builddir@/$@.tmp
	$(AM_V_at)for x in $(YELP_STATIC_HTML); do \
		if test -e "$$x"; then \
			cp "$$x" @abs_builddir@/$@.tmp; \
		fi; \
	done
	$(AM_V_at)cp $(MAN_HTML_FILES) @abs_builddir@/$@.tmp
	$(AM_V_at)cp $(MAN_XML_FILES) @abs_builddir@/$@.tmp
	$(AM_V_at)cp $(BONUS_FILES) @abs_builddir@/$@.tmp
	$(AM_V_at)cp -r api/html @abs_builddir@/$@.tmp/api
	$(AM_V_at)mv $@.tmp $@

dbus-docs.tar.xz: dbus-docs
	$(AM_V_GEN)tar --xz -c -f $@ $<

DOC_SERVER = dbus.freedesktop.org
DOC_WWW_DIR = /srv/dbus.freedesktop.org/www

SPECIFICATION_SERVER = specifications.freedesktop.org
SPECIFICATION_PATH = /srv/specifications.freedesktop.org/www/dbus/1.0

maintainer-upload-docs: dbus-docs.tar.xz dbus-docs
	scp dbus-docs.tar.xz $(DOC_SERVER):$(DOC_WWW_DIR)/
	rsync -rpvzP --chmod=Dg+s,ug+rwX,o=rX \
		dbus-docs/ $(DOC_SERVER):$(DOC_WWW_DIR)/doc/
	cd $(srcdir) && scp -p $(dist_dtd_DATA) $(SPECIFICATION_SERVER):$(SPECIFICATION_PATH)/
else
maintainer-upload-docs:
	@echo "Can't upload documentation! Re-run configure with"
	@echo "  --enable-doxygen-docs --enable-xml-docs --enable-ducktype-docs"
	@false
endif

CLEANFILES = \
	$(man1_MANS) \
	$(MAN_XML_FILES) \
	$(XMLTO_HTML) \
	$(YELP_HTML) \
	$(YELP_STATIC_HTML) \
	$(NULL)

clean-local:
	rm -f $(html_DATA)
	rm -rf api
	rm -rf dbus-docs dbus-docs.tmp
	rm -f *.1.html
	rm -f doxygen.stamp
